﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentWeb.DAL;
using StudentWeb.Model;
using StudentWeb.Common;

namespace StudentWeb.BLL
{
    public class BookBO
    {
        #region 书籍单条
        /// <summary>
        /// 书籍信息 分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="wc"></param>
        /// <returns></returns>
        public IResult GetBookinfo(int BookID)
        {
            var res = new BookDataDAO().GetInfo(BookID);
            return new DataResult<BookData>(res);
        }
        #endregion

        #region 书籍信息 删除单条记录
        ///<summary>
        ///书籍信息 删除单条记录
        ///</summary>
        ///<param name = "BookID" ></ param >
        ///< returns ></ returns >
        public IResult DeleteBookInfo(int BookID)
        {
            int res = new BookDataDAO().Delete(BookID);
            if (res > 0)
            {
                return new Result(ResultCode.Success);
            }
            return new Result(ResultCode.Fail);
        }
        #endregion

        #region 书籍信息修改单条记录
        public bool UpdateBookInfo(dynamic data)
        {
            int BookID = data.BookID;
            var result = 0;
            var record = new BookDataDAO().GetInfo(BookID);
            record.BookName = data.BookName;
            record.BookNo = data.BookNO;
            result = new BookDataDAO().Update(record);
            return result > 0;
        }
        #endregion

        #region 书籍信息添加
        public bool SaveBookInfo(dynamic data)
        {
            int BookID = data.BookID ?? 0;
            var result = 0;
            if (BookID > 0)
            {
                var record = new BookDataDAO().GetInfo(BookID);
                record.BookName = data.BookName;
                record.BookNo = data.BookNO;
                result = new BookDataDAO().Update(record);
            }
            else if (BookID == 0)
            {
                var book = new BookData()
                {
                    BookName = data.BookName,
                    BookNo = data.BookNO,
                };
                result = new BookDataDAO().Insert(book);
            }
            return result > 0;
        }

        #endregion
    }
}